/**
 * @description: 查找树节点
 * @param origin 数据源
 * @param findValue 找到节点
 * @param key 默认id
 * @return T
 */
function findTreeNode(origin, findValue, key = "id") {
    let result = null;
    const fun = (data) => {
        if (Array.isArray(data)) {
            for (let i = 0; i < data.length; i++) {
                let item = data[i];
                if (item[key] === findValue) {
                    result = item;
                    return;
                }
                if (item.children && item.children.length) {
                    fun(item.children);
                }
            }
        }
    };
    fun(origin);
    return result;
}

export { findTreeNode };
